package com.cb.spzx.manager.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.cb.spzx.model.entity.product.Brand;
import com.cb.spzx.manager.service.BrandService;
import com.cb.spzx.manager.mapper.BrandMapper;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
* @author lenovo
* @description 针对表【brand(分类品牌)】的数据库操作Service实现
* @createDate 2024-04-13 16:01:25
*/
@Service
public class BrandServiceImpl extends ServiceImpl<BrandMapper, Brand> implements BrandService{

    @Override
    public IPage<Brand> findByPage(Page<Brand> brandPage) {
        LambdaQueryWrapper<Brand> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.orderByDesc(Brand::getCreateTime);
        return baseMapper.selectPage(brandPage,queryWrapper);
    }

    @Override
    public int saveBrand(Brand brand) {
        return baseMapper.insert(brand);
    }

    @Override
    public void updateBrandById(Brand brand) {
        brand.setUpdateTime(new Date());
        baseMapper.updateById(brand);
    }

    @Override
    public void deleteById(Long id) {
        baseMapper.deleteById(id);
    }

    @Override
    public List<Brand> findAll() {
        LambdaQueryWrapper<Brand> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.orderByDesc(Brand::getId);
        return baseMapper.selectList(queryWrapper);
    }
}




